package com.shujia.wyh.day12;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

/*
    字符流：(所有的写都需要刷新)
        字符输入流：Reader
        字符输出流：Writer -- 子类：OutputStreamWriter
 */
public class WriterDemo2 {
    public static void main(String[] args) throws Exception {
        //创建字符输出流对象
        //public OutputStreamWriter(OutputStream out)
//        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("java/src/com/shujia/wyh/day12/d.txt"));

        //public OutputStreamWriter(OutputStream out,String charsetName)
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("java/src/com/shujia/wyh/day12/d.txt"),"GBK");

        //字符输出流写数据的方式：
        //public void write(int c)
        //一次写一个字节
        osw.write(97);
        osw.flush();

        //public void write(char[] cbuf)
        //一次写一个字符数组
        String s = "今天的天气依旧很糟糕。";
        osw.write(s.toCharArray());
        osw.flush();

        //public void write(char[] cbuf,int off,int len)
        //写字符数组的一部分
        char[] chars = {'q','w','e','r'};
        osw.write(chars,1,2);
        osw.flush();

        //public void write(String str)
        //直接写一个字符串
        osw.write("好好学习，天天向上！");
        osw.flush();

        //public void write(String str,int off,int len)
        //写字符串的一部分
        osw.write("吴涛是真的很帅！",0,2);
        osw.flush();


        //释放资源
        osw.close();

    }
}
